<%--
  Created by IntelliJ IDEA.
  User: ddd
  Date: 2018/4/17
  Time: 11:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>套题复制</title>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="/static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/static/css/animate.min.css" rel="stylesheet">
    <link href="/static/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/css/admin.css">

</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="container">
        <div class="row">
            <%--第一级选项卡--%>
            <div class="col-sm-12">
                <div class="tabs-container" id="tabss">
                    <input type="hidden" id="taoti" value="">
                    <ul class="nav nav-tabs" id="pan"></ul>
                    <div class="tab-content" id="cont"></div>
                    <button class="btn btn-primary btn-block" onclick="CopySecondTypeTo()">复制</button>
                </div>
            </div>
        </div>
    </div>

</div>

<script src="/static/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/static/js/content.min.js?v=1.0.0"></script>
<script src="/static/layer/layer.js"></script>
<script src="/static/js/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="/static/js/plugins/bootstrap-table/bootstrap-table-mobile.js"></script>
<script src="/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
</body>
</html>

<script>
    var arr = [];

    $.ajax({
        url: '/levelAndSecond',
        type: 'get',
        dataType: 'json',
        async: false,
        success: function (json) {
            $.each(json.uservos, function (i, v) {
                if (i === 0) {
                    $("#pan").append("<li class='active'><a data-toggle='tab' href='#tab-" + i + "' aria-expanded='true'>" + v.title + "</a></li>");
                } else {
                    $("#pan").append("<li><a data-toggle=\"tab\" href=\"#tab-" + i + "\" >" + v.title + "</a></li>");
                }
                if (i === 0) {
                    $("#cont").append("<div id=\"tab-" + i + "\" class='tab-pane active'><div class='panel-body'><div class=\"col-sm-12\"><div class=\"tabs-container\"><ul class=\"nav nav-tabs\" id='pan-" + i + "'></ul><div class='tab-content' id='pan-ten-" + i + "'></div></div></div></div></div>");
                } else {
                    $("#cont").append("<div id='tab-" + i + "' class=\"tab-pane\"><div class='panel-body'><div class=\"col-sm-12\"><div class=\"tabs-container\"><ul class=\"nav nav-tabs\" id='pan-" + i + "'></ul><div class='tab-content' id='pan-ten-" + i + "'></div></div></div></div></div>");
                }
                $.each(json.uservos[i].courseVoEnhances, function (j, v) {
                    //科目一 科目四
                    if (j === 0) {
                        $("#pan-" + i + "").append("<li class='active'><a data-toggle='tab' href='#tab-" + i + "-" + j + "'  aria-expanded='true' >" + v.name + "</a></li>");
                    } else {
                        $("#pan-" + i + "").append("<li><a data-toggle='tab' href='#tab-" + i + "-" + j + "' >" + v.name + "</a></li>");
                    }
                    //内容
                    if (j === 0) {
                        $("#pan-ten-" + i + "").append("<div id='tab-" + i + "-" + j + "' class='tab-pane active'><div class='panel-body' id='pan" + i + "-body" + j + "'></div></div>");
                    } else {
                        $("#pan-ten-" + i + "").append("<div id='tab-" + i + "-" + j + "' class='tab-pane'><div class='panel-body' id='pan" + i + "-body" + j + "'></div></div>");
                    }
                    $("#tab-" + i + "-" + j + "> .panel-body").append("<table data-mobile-responsive='true' exid='" + v.id + "' id='table-" + i + "-" + j + "' ></table>");
                    var $iddd = $("#table-" + i + "-" + j + "");
                    $iddd.bootstrapTable({
                        striped: true,
                        data: v.exertypeVos,
                        height: 420,
                        sidePagination: "client",
                        pagination: true,
                        pageNumber: 1,
                        pageSize: 10,
                        pageList: [],
                        clickToSelect: true,
                        sortName: 'px',
                        sortOrder: 'asc',
                        uniqueId: "id",
                        columns: [
                            {
                                checkbox: true
                            }, {
                                field: 'id',
                                title: 'ID'
                            }, {
                                field: 'name',
                                title: '题型名称'
                            }
                        ]
                    })
                })
            });
            arr.push(json);
            arr = arr[0]
        }
    });

    function closewin() {
        var ind = parent.layer.getFrameIndex(window.name);
        parent.layer.close(ind)
    }

    function CopySecondTypeTo() {
        var exids = [];
        var list = [];
        var taoti = $("#taoti").val().split(",");
        var $table = $("table[id]");
        $.each($table, function (k, v) {
            var idd = '#' + v.id;
            var ar = $(idd).bootstrapTable('getSelections');
            if (ar.length) {
                $.each(ar, function (k, v) {
                    exids.push(v.id)
                })
            }
        });
        //将要复制到的题型
        //console.info(exids);
        //要复制的套题id
        //console.info(taoti);
        //list(id(复制套题的id),name,exid,imgpath,px)
        $.each(taoti, function (k, tid) {
            $.each(arr.uservos, function (i, v1) {
                $.each(v1.courseVoEnhances, function (j, v2) {
                    $.each(v2.exertypeVos, function (k, v3) {
                        //题型
                        $.each(v3.secondTypes, function (s, v) {
                            //套题
                            if (v.id == tid) {
                                $.each(exids, function (l, v4) {
                                    list.push({id: v.id, name: v.name, exid: v4, imgpath: v.imgpath, px: v.px})
                                })
                            }
                        })
                    })
                })
            })
        });

        if (taoti.length === 0) {
            layer.msg('请选择数据')
        } else {
            layer.confirm('确定是否复制套题', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: '/copySecondTypes',
                    contentType: 'application/json;charset=UTF-8',
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify(list),
                    success: function (json) {
                        if (json.status === "success") {
                            layer.msg('操作成功', {icon: 1, time: 1000});
                            setTimeout(function () {
                                var index=window.parent.layer.getFrameIndex(window.name);
                                window.parent.layer.close(index);
                            }, 1200);
                        } else {
                            layer.msg(json.status, {icon: 2, time: 1000});
                            setTimeout("closewin()",2000);
                        }
                    },
                    error: function () {
                        layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
                        setTimeout("closewin()",2000);
                    }
                })
            }, function () {
                layer.msg('取消操作成功', {icon: 1, time: 1000});
            });
        }
    }


</script>
